//
//  VisitorTableViewController.swift
//  weibo1990
//
//  Created by 曹晓龙 on 15/10/17.
//  Copyright © 2015年 曹晓龙. All rights reserved.
//

import UIKit

/// 未登录界面
class VisitorTableViewController: UITableViewController {

    private var isLogin = OauthViewModel.sharedOauthViewModel.isLogin
    
    var visitorView:VisitorView?
    
    override func loadView() {
        
         isLogin ? super.loadView() : setupLoadView()
        
    }
    
    ///  设置启动根视图
    func setupLoadView(){
        
        visitorView = VisitorView()
        
        view = visitorView
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerBtnClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginBtnClick")
                
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        visitorView?.loginBtn.addTarget(self, action: "loginBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.registerBtn.addTarget(self, action: "registerBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
    }

}

// MARK: - 按钮的点击时间
extension VisitorTableViewController {
    
    ///  点击登录按钮
    @objc private func loginBtnClick(){
        
        let vc = OauthViewController()
        
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
    /// 点击注册按钮
    @objc private func registerBtnClick(){
        print("点击了注册按钮")
    }
    
    
}